import pandas as pd
import numpy as np
from gensim.models import Word2Vec


keywords_df = pd.read_csv('../data/keywords_all.csv')
word_model = Word2Vec.load('../model/word_vec.model')
keyword_vector = []
error_words = []
for words in keywords_df['keywords']:
    word_list = words.split(' ')
    word_vector_list = []

    for word in word_list:
        try:
            word_vector_list.append(word_model[word])
        except:
            error_words.append(word)
            print('%s is not exist', word)
    vectors = np.array(word_vector_list)
    vectors_mean = np.mean(vectors, 0)
    keyword_vector.append(vectors_mean)

print(len(error_words))
vector = np.array(keyword_vector)
np.savetxt('../model/keyword_word2vec.csv', vector, delimiter = ',')